package net.anzhuo.service.impl;

import lombok.extern.slf4j.Slf4j;
import net.anzhuo.common.entity.PaginationVO;
import net.anzhuo.dao.GsContractsMapper;
import net.anzhuo.entity.GsContracts;
import net.anzhuo.service.GsContractsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Slf4j
public class GsContractsServiceImpl implements GsContractsService {

	@Autowired
	private GsContractsMapper gsContractsMapper;

	@Override
	public PaginationVO<GsContracts> getListWithPage(GsContracts gsContracts) {
		PaginationVO<GsContracts> paginationVO = new PaginationVO<>();
		paginationVO.setList(gsContractsMapper.getListWithPage(gsContracts));
		paginationVO.setTotalCount(gsContractsMapper.getCount(gsContracts));
		paginationVO.setTotalPage((gsContractsMapper.getCount(gsContracts) + gsContracts.getPageSize() -1)  / gsContracts.getPageSize());
		paginationVO.setPageNo(gsContracts.getPageNo());
		return paginationVO;
	}

	@Override
	public List<GsContracts> getByMd5(String md5) {
		return gsContractsMapper.getByMd5(md5);
	}

	@Override
	public GsContracts getById(Long id) {
		return gsContractsMapper.getById(id);
	}

	@Override
	public List<GsContracts> getList() {
		return gsContractsMapper.getList();
	}

	@Override
	public List<GsContracts> getList(GsContracts gsContracts) {
		return gsContractsMapper.getListByQuery(gsContracts);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void update(GsContracts gsContracts) {
		gsContractsMapper.update(gsContracts);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void save(GsContracts gsContracts) {
		gsContractsMapper.save(gsContracts);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void delete(Long id) {
		GsContracts gsContracts = gsContractsMapper.getById(id);
		if (gsContracts == null) {
//			ExceptionUtil.throwAppException(ResultEnum.ILLEGAL_OPERATION);
			return;
		}
		gsContractsMapper.update(gsContracts);
	}
}
